package cn.edu.ujn.lab3.service;

import cn.edu.ujn.lab3.dao.Record;
import cn.edu.ujn.lab3.dao.RecordMapper;
import cn.edu.ujn.lab3.utils.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 车辆出入记录Service接口实现类
 */
@Service("recordService")
@Transactional
public class RecordServiceImpl implements RecordService {
	// 注入orderMapper
	@Autowired
	private RecordMapper recordMapper;


    @Override
    public Page<Record> findRecordList(Integer page, Integer rows, Integer cId, Integer vId, String vehicleNo, Integer pId, String state) {
        Record record = new Record();
        record.setcId(cId);
        record.setvId(vId);
        record.setVehicleNo(vehicleNo);
        record.setState(state);
        record.setpId(pId);
        // 当前页
        record.setStart((page-1) * rows) ;
        // 每页数
        record.setRows(rows);
        // 查询记录列表
        List<Record> records =
                recordMapper.selectRecordList(record);
        // 查询客户列表总记录数
        Integer count = recordMapper.selectRecordListCount(record);
        // 创建Page返回对象
        Page<Record> result = new Page<>();
        result.setPage(page);
        result.setRows(records);
        result.setSize(rows);
        result.setTotal(count);
        return result;
    }

    @Override
    public int createRecord(Record Record) {
        return recordMapper.insert(Record);
    }

    @Override
    public int updateRecord(Record Record) {
        return recordMapper.updateByPrimaryKey(Record);
    }

    @Override
    public int deleteRecord(Integer id) {
        return recordMapper.deleteByPrimaryKey(id);
    }

    @Override
    public Record getRecordById(Integer id) {
        return recordMapper.selectByPrimaryKey(id);
    }
}
